using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using LeisureCenter.Api;
using LeisureCenter.Controls;

namespace LeisureCenter.Forms
{
    public partial class ListDialog : DialogControl
    {
        public ListDialog()
        {
            InitializeComponent();
            lbList.ItemSelected += new EventHandler(lbList_ItemSelected);
        }

        public static bool Execute(IEnumerable<string> items, bool showCancel, ref int index, Color alphaBackgroundColor)
        {
            ListDialog listDialog = new ListDialog();
            foreach (string item in items)
                listDialog.lbList.Items.Add(new ListBoxItem(listDialog.lbList, item, ""));
            if (index >= 0 && index < listDialog.lbList.Items.Count)
                listDialog.lbList.SelectedIndex = index;
            listDialog.ShowCancelButton = showCancel;
            listDialog.AlphaBackgroundColor = alphaBackgroundColor;
            bool result = listDialog.Execute();
            if (result)
                index = listDialog.lbList.SelectedIndex;
            return result;
        }

        private void lbList_ItemSelected(object sender, EventArgs e)
        {
            if (this.ParentForm != null)
                this.ParentForm.DialogResult = DialogResult.OK;
        }

        public override void SetFocusHandlers(IFocusHandler okButton, IFocusHandler cancelButton)
        {
            lbList.FocusRight = cancelButton;
        }
    }
}
